package com.wbf.demo.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: shiroDemo
 * @description: 请求日志收集器
 * @author: guangdao
 * @create: 2022-04-29 15:53
 **/
@Slf4j
@Component
public class RequestLogFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
        log.info("{} {}", request.getMethod(), request.getRequestURI());
        chain.doFilter(request, response);
        log.info("status {}", response.getStatus());
    }
}
